package de.stefanocke.roo.wicket.details;

import java.util.List;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.classpath.itd.ItdTypeDetailsProvidingMetadataItem;

import de.stefanocke.roo.wicket.RooDetails;
import de.stefanocke.roo.wicket.Stereotypes;
import de.stefanocke.roo.wicket.base.BeanPropertiesAwareMetadataProvider;
import de.stefanocke.roo.wicket.base.ModelClassAwareMetadataCreationParams;
import de.stefanocke.roo.wicket.model.BeanPropertyMetadata;
import de.stefanocke.roo.wicket.model.BeanPropertyMetadataWithDetails;

/**
 * Provides {@link DetailsMetadata}.
 * 
 */
@Component
@Service
public final class DetailsMetadataProvider extends
		BeanPropertiesAwareMetadataProvider<DetailsMetadata, DetailsAnnotationValues> {

	private static final String[] STEREOTYPES = new String[] {Stereotypes.DETAILS, Stereotypes.LIST_VIEW, Stereotypes.IENTITYBINDINGS};

	public DetailsMetadataProvider() {
		super(RooDetails.class, DetailsMetadata.class, DetailsAnnotationValues.class, DetailsComponentMetadata.class);
	}

	@Override
	protected Class<DetailsHtmlBuilder> getHtmlBuilderClass() {
		return DetailsHtmlBuilder.class;
	}

	@Override
	protected ItdTypeDetailsProvidingMetadataItem getMetadataInternal(
			ModelClassAwareMetadataCreationParams<DetailsAnnotationValues> cmcp) {
		List<BeanPropertyMetadata> propertyMetadata = getBeanPropertiesMetadata(cmcp);

		List<BeanPropertyMetadataWithDetails<DetailsComponentMetadata>> detailsPropertyMetadata = createBeanPropertyMetadataWithDetails(
				cmcp.getMid(), propertyMetadata, DetailsComponentMetadata.class);

		DetailsMetadata detailsMetadata = new DetailsMetadata(cmcp, detailsPropertyMetadata);
		return detailsMetadata;
	}

	@Override
	protected String[] requiredStereotypes() {
		return STEREOTYPES;
	}

}